﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UtilsExtensionsAndHelpers.Utils
{
    /// <summary>
    /// An interface for SCUD
    /// </summary>
    /// <typeparam name="TEntity">Type of item this repository will contain.</typeparam>
    /// <typeparam name="TId">Type of identifier for the item, usually int or Guid </typeparam>
    public interface IRepository<TEntity, in TId> where TEntity : IEntity<TId>
    {
        /// <summary>
        /// Creates a new entity for this repository.
        /// Essentially abstracts the constructors
        /// </summary>
        Func<TEntity> New { get; set; }

        /// <summary>
        /// Creates a new entity for this repository.
        /// Essentially abstracts the constructors
        /// </summary>
        Action<TEntity> SetNewId { get; set; }

        /// <summary>
        /// If the item is in the repository returns true else false.
        /// </summary>
        bool Exists(TId id);

        /// <summary>
        /// Get an item by id
        /// </summary>
        TEntity Get(TId id);

        /// <summary>
        /// Save will update an existing record or create a record if it doesn't exist.
        /// </summary>
        /// <param name="item">Item you want to save</param>
        /// <returns>The item you passed in with any create info added to it, such as an id.</returns>
        TEntity Save(TEntity item);

        /// <summary>
        /// List of items in the repository
        /// </summary>
        IEnumerable<TEntity> List();

        /// <summary>
        /// Deletes an item from the repository
        /// </summary>
        void Delete(TEntity item);

        /// <summary>
        /// Deletes an item from the repository
        /// </summary>
        void Delete(TId id);

    }
}
